<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>添加权限</title>
    <link rel="stylesheet" href="/static/lib/layuiadmin/plugins/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="/static/lib/layuiadmin/css/global.css" media="all">
    <link rel="stylesheet" href="/static/lib/layuiadmin/plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="/static/lib/layuiadmin/css/table.css" />
</head>

<body>
<div class="admin-main">

    <div style="margin: 15px;">
        <form class="layui-form" method="post" action="/admin/download/create">

            <div class="layui-form-item">
                <label class="layui-form-label">标题</label>
                <div class="layui-input-block">
                    <input type="text" name="title" required lay-verify="required" placeholder="请输入文件标题" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">描述</label>
                <div class="layui-input-block">
                    <input type="text" name="desc"   placeholder="请输入文件描述" autocomplete="off" class="layui-input">
                </div>
            </div>


            <div class="layui-form-item">
                <label class="layui-form-label">分类</label>
                <div class="layui-input-block">
                    <select name="cate" lay-verify="required">
                        <option value=""></option>
                        <{volist name="category" id="item"}>
                        <option value="<{$item.id}>"   ><{$item.name}></option>
                        <{/volist}>
                    </select>
                </div>
            </div>


            <div class="layui-form-item">
                <label class="layui-form-label">封面</label>
                <div class="layui-input-block">
                    <img src="/uploads/20181105/de7c9c75f734225ed7018d5032a4e2af.jpg" style="width:200px;height:200px;" id="cover-show"/>
                    <img src="/static/images/loading.gif" id="loading" style="display:none;" />
                    <div style="color:red;">建议大小：475*300</div>
                    <div style="margin-top: 10px;"><input type="file" name="file" class="layui-upload-file" lay-type="file"></div>
                    <input type="hidden" value="" id="cover"  name="cover"/>
                </div>
            </div>

            <input type="hidden" value="" id="file_id" name="file_id" />



            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button lay-filter="add" lay-submit class="layui-btn">提交</button><a href="/admin/download/index" class="layui-btn layui-btn-danger">返回</a>
                </div>
            </div>
        </form>
    </div>


</div>
<script type="text/javascript" src="/static/lib/layuiadmin/plugins/layui/layui.js"></script>


<script type="text/javascript">
    layui.use('form', function(){
        var form = layui.form();
    });
    layui.use(["layer","upload"],function(){
        var $ = layui.jquery;
        layui.upload({
            url: '/admin/upload/upload'
            ,success: function(res){
                console.log(res); //上传成功返回值，必须为json格式
                if(1 == res.code){
                    $("#cover-show").attr("src","/uploads/20181105/b8016c14b755b18e71d3eef7b28cce17.jpg");
                    $("#cover").val(res.data.src);
                    $("#file_id").val(res.data.id);
                    $("#loading").hide();
                }else{
                    layer.msg(res.msg);
                }
            },
            before: function(input){
                //返回的参数item，即为当前的input DOM对象
                $("#loading").show();
            }
        });
    });

</script>

</body>

</html>